package com.kjc.demo.basic.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.kjc.demo.basic.config.MyConfig;
import com.kjc.demo.basic.config.ServerConfig;

import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping(value = "/testdemo")
@Slf4j
public class TestController {
	
	@Autowired
	ServerConfig serverConfig;
	
	@Autowired
	MyConfig myConfig;
	
	@Value("${app.description}")
	private String appDesc;
	
	@GetMapping("/getPortAndIp")
	public String setredisvalue(HttpServletRequest request) {
		String ip = serverConfig.getUrl();
		Integer port = serverConfig.getServerPort();
		log.info("ip:{};port:{}",ip,port);
		return ip + "--" +port;
	}
	
	@GetMapping("/getMyconfig")
	public String getMyconfig(HttpServletRequest request) {
		String number = myConfig.getNumber();
		Long bigNumber = myConfig.getBignumber();
		String uuid = myConfig.getUuid();
		String secret = myConfig.getSecretl();
		List<String> servers = myConfig.getServers();
		log.info(JSON.toJSONString(servers));
		log.info("number:{};bigNumber:{};uuid:{};secret:{}",number,bigNumber,uuid,secret);
		return number + "--" +bigNumber+"---"+uuid+"---"+secret;
	}
	
	@GetMapping("/getDesc")
	public String getDesc(HttpServletRequest request) {
		return this.appDesc;
	}
}
